home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / program / readme12.arc / README12.C < prev    next >
C/C++ Source or Header  |  1988-06-29  |  17KB  |  588 lines

  1.                /* README.PRG Vers. 1.0 By Todd Burkey, 6/1/88. */
  2. /* Version 1.1 6/10/88-Todd Burkey: Added Color selection and Tab support */
  3. /* Version 1.2 6/19/88-Todd Burkey: Started code setup for menu overlays  */
  4.  
  5. /* The source code and accompany text files (MENU.TRB and README.TRB) must
  6.    always accompany the README.PRG file (ARC'ed as a package).             */
  7.  
  8. /*
  9.    This program shows one use of the POPHELP mechanism (Copyright 1988 by
  10.    Todd Burkey). POPHELP is intended to be a 'clean' way of presenting help
  11.    to users of a program and was also written to demonstrate in source code
  12.    how to do those confusing linea/vdi/etc things that all of our manuals kind
  13.    of gloss over. I am not saying that my methods are proper coding or even
  14.    close, but at least it works. In order to ensure that this code and the
  15.    techniques involved stay accessible to the public at large, I have to make
  16.    the following stipulations:
  17.  
  18.      1) This program and source code may be freely distributed as long as no
  19.         profits are made in the process (Club Disks of the Month and BBS's are
  20.         excepted, of course.)
  21.      2) All derivatives of the routines in this code must include this notice
  22.         verbatim and are similarly subject to the conditions in 1, above.
  23.      3) No warrantees are made as to the usefulness or safety of using this
  24.         code. The user uses it at his/her own risk.
  25.  
  26.          -Todd Burkey    "A member of STdNET-The ST developers' Network"
  27.           trb@stag.UUCP
  28.           3546 Pilgrim Lane
  29.           Plymouth, MN 55441
  30. */
  31.  
  32. #include <linea.h>
  33. #include <ctype.h>
  34. #include <stdio.h>
  35. #include <aesbind.h>
  36. #include <osbind.h>
  37. #include <vdibind.h>
  38. #include <bios.h>
  39.  
  40. #define RESTORE 1
  41. #define SAVE 2
  42. #define ONLYTEXT 1
  43. #define MOREHELP 2
  44. #define ESC 27
  45. #define HELP 98
  46. #define UPARROW 72
  47. #define DOWNARROW 80
  48. #define LEFTARROW 75
  49. #define RIGHTARROW 77
  50. #define LEFTBUTTON 0x740000L
  51. #define RIGHTBUTTON 0x750000L
  52. #define MAX_MENUS 100
  53.  
  54. /* and now some necessary vdi/aes stuff */
  55. int h,xy[16],contrl[12],intin[128],ptsin[128],intout[128],ptsout[128];
  56. int src[11];
  57. int scr_a[] = {  0, 0, 640, 200, 40, 0, 2, 0, 0, 0 };
  58. char *oldscr,*newscr,*memblk;
  59.  
  60. /* and now for the POPMENU related arrays */
  61. int menu_col[MAX_MENUS+1],     /* upper left column number for menu */
  62.     menu_row[MAX_MENUS+1],     /* upper left row number for menu */
  63.     menu_fr[MAX_MENUS],        /* first character in menu_s for the menu */
  64.     menu_to[MAX_MENUS],        /* last character in menu_s for the menu */
  65.     menu_last[MAX_MENUS],      /* previous menu that you viewed */
  66.     on_line[MAX_MENUS],        /* what line were you last on? */
  67.     menu_rgb[MAX_MENUS+1][4];  /* color rgb map for menu */
  68. char menu_s[30000];
  69. int error_cnt=0;
  70. int which;                     /* which menu are we on */
  71. int menu_length,               /* length (height) of current menu */
  72.     menu_width,                /* width of current menu */
  73.     lc1,lc2,lr1,lr2,           /* last corners (col/row) of menu box */
  74.     menu_ptr[24],              /* a menu selections' next menu (forward ptr) */
  75.     menu_type[24];             /* type of menu entry...ONLYTEXT or MOREHELP */
  76. char menu_line[24][130];       /* what you see in the box */
  77. char help_path[100];           /* tbd...for global path lookup... */
  78. int menu_s_pos;                /* tbd...useful if we use menu overlays */
  79.  
  80. /* and some stuff I need */
  81. long tst,vtst;
  82. int htst,mono,black,blue,red,green;
  83. int save_col[4];
  84. long _stksize = 40000L;    
  85. static long patmsk = -1;
  86.  
  87. main()
  88. {
  89.   int i;
  90.   color_init();
  91.   ws_init();             /* do all that messy vdi/linea initialization */
  92.   build_help();          /* build the internal help arrays from menu.trb */
  93.   if(Bconstat(BC_KBD)) Bconout(BC_KBD,0x0a);  /* set mouse cursor mode */
  94.   if(Bconstat(BC_KBD)) Bconout(BC_KBD,0x14);  /* 20 pulses per x move */
  95.   if(Bconstat(BC_KBD)) Bconout(BC_KBD,0x05);  /* 5 pulses per y move */
  96.   mon_keys();
  97.   if(Bconstat(BC_KBD)) Bconout(BC_KBD,0x08);  /* reset mouse mode to normal */
  98.   for(i=0;i<4;i++) Setcolor(i,save_col[i]);
  99.   }
  100.  
  101. color_init()   /* check resolutions and setup accordingly */
  102. {
  103.   int i;
  104.   i=Getrez();
  105.   if(i==0) {
  106.     printf("Sorry, Medium or High Res only\n[Hit any key]\n");
  107.     Crawcin();
  108.     exit(1);
  109.     }
  110.   if(i==2) {
  111.      mono=1;
  112.      black='3';
  113.      blue='3';
  114.      red='3';
  115.      green='0';
  116.      }
  117.   else {
  118.     mono=0;
  119.     black='2';
  120.     blue='0';
  121.     red='1';
  122.     green='2';
  123.     }
  124.   for(i=0;i<4;i++) save_col[i]=Setcolor(i,-1);
  125.   for(i=0;i<=MAX_MENUS;i++) {          /* setup default colors */
  126.     if(mono) menu_rgb[i][0]=0x777;
  127.     else     menu_rgb[i][0]=0x006;
  128.     menu_rgb[i][1]=0x600;
  129.     menu_rgb[i][2]=0x000;
  130.     if(mono) menu_rgb[i][3]=0x000;
  131.     else     menu_rgb[i][3]=0x775;
  132.     }
  133.   set_rgb(0);
  134.   }
  135.  
  136. mon_keys()   /* simple loop that waits for a HELP key or Q key */
  137. {
  138.   while(((tst=Bconin(2))&0xFF)!='Q') {
  139.     tst=tst>>16;
  140.     if(tst==HELP) {
  141.       which=0;
  142.       show_help(1);
  143.       }
  144.     while((Cconis())!=0) Crawcin();
  145.     }
  146.   v_clsvwk(h);
  147.   appl_exit();
  148.   }
  149.  
  150. set_rgb(m)
  151. int m;
  152. {
  153.   Setcolor(0,menu_rgb[m][0]);
  154.   Setcolor(1,menu_rgb[m][1]);
  155.   Setcolor(2,menu_rgb[m][2]);
  156.   Setcolor(3,menu_rgb[m][3]);
  157.   }
  158.  
  159. draw_help(menu)  /* draw the selected help popup */
  160. int menu;
  161. {
  162.   int i,j;
  163. /* First, gather up all of the info for the CURRENT menu to draw */
  164.   menu_length=0;
  165.   if(menu>=MAX_MENUS||menu<0)
  166.     sprintf(menu_line[menu_length++],"ERROR IN MENU.TRB. Menu numbers must be between 0 and 99.");
  167.   else if(menu_fr[menu]<0)
  168.     sprintf(menu_line[menu_length++],"ERROR IN MENU.TRB. Can't Find the menu definition for %d.",menu);
  169.   if(menu_length>0) {
  170.     sprintf(menu_line[menu_length++],"Please fix this problem ASAP. Press the Left Arrow now.");
  171.     menu_width=strlen(menu_line[0]);
  172.     menu_type[0]=menu_type[1]=ONLYTEXT;
  173.     menu=MAX_MENUS;
  174.     menu_col[menu]=4;
  175.     menu_row[menu]=11;
  176.     }
  177.   else if(menu_s[menu_fr[menu]]!='<') {
  178.     for(i=menu_fr[menu],j=0,menu_width=0;i<=menu_to[menu];i++) {
  179.       if(menu_s[i]=='\0') {
  180.         menu_line[menu_length++][j-1]='\0';
  181.         j++;
  182.         if(j>menu_width) menu_width=j;
  183.         j=0;
  184.         }
  185.       else {
  186.         if(j==0&&menu_s[i]=='+') menu_type[menu_length]=MOREHELP;
  187.         else if(j==0&&menu_s[i]=='T') menu_type[menu_length]=ONLYTEXT;
  188.         else if(j==0&&menu_s[i]=='=') {
  189.           menu_ptr[menu_length-1]=atoi(&menu_s[i+2]);
  190.           while(menu_s[i]!='\0'&&i<10000) i++;
  191.           j=0;
  192.           }
  193.         else if(j<=1&&menu_s[i]==':') j++;
  194.         else {
  195.           menu_line[menu_length][j-1]=menu_s[i];
  196.           j++;
  197.           }
  198.         }
  199.       }
  200.     menu_width=menu_width-2;
  201.     }
  202.   else viewfile(menu);
  203.   set_rgb(menu);
  204.   lc1=menu_col[menu];
  205.   lr1=menu_row[menu];
  206.   lc2=lc1+menu_width;
  207.   lr2=lr1+menu_length;
  208. /* Now, save the part of the screen that we are gonna draw on. */
  209.   screen_it(SAVE,lc1,lr1,lc2,lr2);
  210. /* and draw the popup */
  211.   fboxcr(lc1,lr1,lc2,lr2);
  212.   boxcr(lc1,lr1,lc2,lr2); 
  213.   for(i=0;i<menu_length;i++) {
  214.     if(menu_type[i]==ONLYTEXT) {
  215.       if(mono) printcr(lc1,lr1+i,menu_line[i]); /* modify for slant someday */
  216.       else    tprintcr(lc1,lr1+i,menu_line[i]);
  217.       }
  218.     else {
  219.       if(mono) printcr(lc1,lr1+i,menu_line[i]);
  220.       else bprintcr(lc1,lr1+i,menu_line[i]);
  221.       }
  222.     }
  223.   }
  224.  
  225. erase_help()   /* move the stuff we saved to the scratch pad back */
  226. {
  227.   screen_it(RESTORE,lc1,lr1,lc2,lr2);
  228.   }
  229.  
  230. hilite_menu(i)   /* highlight the selection under the cursor */
  231. int i;
  232. {
  233.   if(mono) {
  234.     printcr(lc1,lr1+on_line[which],menu_line[on_line[which]]);
  235.     bprintcr(lc1,lr1+i,menu_line[i]);
  236.     }
  237.   else {
  238.     bprintcr(lc1,lr1+on_line[which],menu_line[on_line[which]]);
  239.     printcr(lc1,lr1+i,menu_line[i]);
  240.     }
  241.   on_line[which]=i;
  242.   }
  243.  
  244. show_help(menu)  /* recursive routine handling the help popup walking */
  245. int menu;
  246. {
  247.   int i,all_text;
  248.   if(which<0) return;
  249.   draw_help(menu);
  250.   on_line[which]=0;
  251.   for(i=0;i<menu_length&&menu_type[i]==ONLYTEXT;i++);
  252.   if(i<menu_length)